package com.scyshkj.university.wechat;

import com.scyshkj.university.wechat.pay.WechatLoginFilter;
import com.scyshkj.university.wechat.wanxiao.WanxiaoOAuthLoginFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 唐旭 on 2016/11/17.
 */
@Configuration
public class OAuthFilterConfig {

    private static List<String> UrlPatterns = new ArrayList<String>();

    static {
        UrlPatterns.add("/pay");
        UrlPatterns.add("/pay/submit");
    }

    @Bean
    public FilterRegistrationBean getWechatLoginFilter() {
        FilterRegistrationBean registrationBean = new FilterRegistrationBean();
        registrationBean.setFilter(new WechatLoginFilter());
        registrationBean.setUrlPatterns(UrlPatterns);
        registrationBean.setOrder(2);
        registrationBean.setName("wechatOAuthFilter");
        return registrationBean;
    }

    @Bean
    public FilterRegistrationBean getWanxiaoLoginFilter() {
        FilterRegistrationBean registrationBean = new FilterRegistrationBean();
        registrationBean.setFilter(new WanxiaoOAuthLoginFilter());
        registrationBean.setUrlPatterns(UrlPatterns);
        registrationBean.setOrder(1);
        registrationBean.setName("wanxiaoLoginFilter");
        return registrationBean;
    }
}
